package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.JlcxDaoljc;
import com.zr.util.JDBCUtil;

public class JlcxDaoImplljc implements JlcxDaoljc{

	@Override
	public int countAllJL() {
		int count = 0;
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(applyscore.id) as count ");
		sql.append(" FROM applyscore");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				count =Integer.parseInt(rs.getString("count"));
			}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
	//教师记录总数
	@Override
	public int countAllJLBytname(String tname) {
		int count = 0;
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(teablog.id) as count ");
		sql.append(" FROM teablog where tname=?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setString(1, tname);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				count =Integer.parseInt(rs.getString("count"));
			}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
	//通过教师id查找教师姓名
	@Override
	public String findTnameByTid(int tid) {
		String tname ="";
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT tname  ");
		sql.append(" FROM teacher where tid=?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setInt(1, tid);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				tname = rs.getString("tname");
			}	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return tname;
	}

}
